
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>



int main()
{
    int outfd;
    outfd = open("outfile.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
    if (outfd == -1)
    {
        perror("open");          
        exit(EXIT_FAILURE);
        close(outfd);
        return 0;
    }

    int infd;
    infd = open("infile.txt", O_RDONLY);
    if (outfd == -1){
        perror("open");          
        exit(EXIT_FAILURE);
        close(infd);
        return 0;

    }
    char buf[1024];
    int n;
    while ((n = read(infd, buf, 1024)) > 0)
    {
        write(outfd, buf, n);
    }
    close(infd);
    close(outfd);
    unlink("tp");
    return 0;
}